from django.views import View

# 导入解析用户信息函数
# 获取数据库连接
from SaaSDevelTool.data_mysql_data import db
# 判断梯队位置
from SaaSDevelTool.data_operation import is_number
# 导入返回响应
from SaaSDevelTool.data_return_response import create_response
# 导入错误信息装饰器
from SaaSDevelTool.data_return_response import error_message_detection

"""功能包梯队位置添加"""


class SaaSDevelModelPackAgeLevelPackageQuery(View):
    @error_message_detection
    def get(self, request):
        # 获取大模块编号
        md_id = request.GET.get("md_id")
        # 判断大模块编号
        if not md_id:
            return create_response(code=400, msg="未传递大模块编号。")
        # 判断大模块编号类型
        if not is_number(md_id):
            return create_response(code=400, msg="大模块编号类型传递错误。")

        # 拼接查询的sql语句
        query_sum_package_table_sql = """
            SELECT 
                package_id,
                package_name 
            FROM 
                db_saas_center.sum_package_table 
            WHERE  
                package_id not in (
                    SELECT 
                        echelon_package_id 
                    FROM 
                        db_saas_center.sum_package_level
                ) 
            AND  
                model_id = {}
            ;""".format(md_id)
        # 获取对应的数据
        query_sum_package_table_data = db.findAll(query_sum_package_table_sql)
        # 返回对应的功能包
        return create_response(code=200, msg="", data=query_sum_package_table_data)
